'use strict';
import ChoiceDialog from '../../common-component/choice-dialog/choice-dialog';
import classifyDialog from '../../common-component/classify-dialog/classify-dialog';
import TimeDialog from '../../common-component/time-dialog/time-dialog.js';
import Api from '../../api/Api';

module.exports = {
    /**
     * 公用dialog
     * @param title
     * @param filter
     * @param table
     * @param url
     * @param complete(select)
     * @param init(ele, obj)
     * @param select
     */
    _createModal: function(title, filter, table, url, complete, init, select = 'radio'){
        return new ChoiceDialog({
            title: title,
            filter: filter,
            table: table,
            url: url,
            select: select || 'radio',
            complete: complete,
            init: init
        })
    },
    /**
     * 查询品牌
     *  @param callback
     */
    _queryBrand: function(callback) {        
        const title = '选择商品品牌信息',
              filter = [{name: '品牌编码', column: 'brandCode'},{name: '品牌名称', column: 'brandName'}],
              table = [{name: '编号', column: 'id'},{name: '品牌编码', column: 'brandCode'},{name: '品牌名称', column: 'brandName'}],
              url = Api.queryBrandInfo;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 查询品类
     * @param callback
     */
    _queryCategory: (callback) =>{
        classifyDialog((obj)=>{
            callback(obj);
        })
    },
    /**
     * 查询商品
     *  @param callback
     */
    _queryGood: function(callback) {
        const title = '选择商品信息',
            filter = [{name: '商品编码', column: 'goodCode'},{name: '商品名称', column: 'goodName'},
                {name: '商品分类', column: 'goodCate'},{name: '商品品牌', column: 'bandName'}],
            table = [{name: '商品编码', column: 'goodCode'},{name: '商品名称', column: 'goodName'},
                {name: '商品分类', column: 'goodCate'},{name: '品牌', column: 'brandName'},
                {name: '商品类型', column: 'goodType'},{name: '计量单位', column: 'cntUnit'},
                {name: '条码', column: 'barCode'},{name: 'SWBM', column: 'gstcValue'},],
            url = Api.queryInstallGood;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 查询销售公司
     *  @param callback
     */
    _querySalesCompany: function(callback) {
        const title = '选择销售公司信息',
            filter = [{name: '销售组织', column: 'saleGroupName'},{name: '公司名称', column: 'companyName'}],
            table = [{name: '编号', column: 'id'},{name: '销售组织', column: 'saleGroupName'},{name:'公司名称', column: 'companyName'}],
            url = Api.querySaleCompany;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 查询售后公司
     *  @param callback
     */
    _queryAfterCompany: function(callback) {
        const title = '选择售后公司信息',
            filter = [{name: '售后公司代码', column: 'companyCode'},{name: '售后公司名称', column: 'companyName'}],
            table = [{name: '售后公司代码', column: 'companyCode'},{name:'售后公司名称', column: 'companyName'}],
            url = Api.queryAfterCompany;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 查询售后公司
     *  @param callback
     */
    _queryRepairCompany: function(callback) {
        const title = '选择售后公司信息',
            filter = [{name: '售后组织', column: 'brandCode'},{name: '公司名称', column: 'brandName'}],
            table = [{name: '编号', column: 'id'},{name: '售后组织', column: 'brandCode'},{name:'公司名称', column: 'brandName'}],
            url = '/';
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 查询服务区域
     *  @param callback
     */
    _queryServiceArea: function(callback) {     
        const title = '选择区域信息',
            filter = [
                {name: '区域代码', column: 'areaCode'},
                {name: '区域名称', column: 'areaName'},
                {name: '省/市', column: 'province'},
                {name: '区/县', column: 'district'}
            ],
            table = [
                {name: '区域代码', column: 'areaCode'},
                {name: '区域名称', column: 'areaName'},
                {name: '省/市', column: 'province'},
                {name: '区/县', column: 'district'},
                {name: '公司代码', column: 'companyCode'},
                {name: '公司名称', column: 'companyName'},
            ],
            url = Api.queryArea;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 维修网点
     * @param callback
     * @param levelEnum //一级 二级网点
     */
    _queryRepairingBlock: function(callback, levelEnum) {     
        const title = '选择网点信息',
            filter = [
                {name: '网点编码', column: 'stationCode'},
                {name: '网点名称', column: 'stationName'},
                {name: '网点类型', column: 'brandCode'}
            ],
            table = [
                {name: '编号', column: 'id'},
                {name: '网点编码', column: 'stationCode'},
                {name: '网点名称', column: 'stationName'},
                {name: '网点类型', column: 'brandName'}
            ],
            url = Api.queryStationBases;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 选择人员信息
     * @param callback
     */
    _queryWorker: function(callback) {     
        const title = '选择人员信息',
            filter = [
                {name: '人员编码', column: 'code'},
                {name: '人员名称', column: 'name'},
                {name: '所属部门', column: 'brandCode'}
            ],
            table = [
                {name: '人员编码', column: 'employeeCode'},
                {name: '人员名称', column: 'employeeName'},
                {name: '所属部门', column: 'brandName'}
            ],
            url = Api.queryEmployee;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 选择商品信息
     * @param callback
     */
    _queryProduct: function(callback) {
        const title = '选择商品信息',
            filter = [
                {name: '商品编码', column: 'goodCode'},
                {name: '商品名称', column: 'goodName'}
            ],
            table = [
                {name: '商品编码', column: 'goodCode'},
                {name: '商品名称', column: 'goodName'}
            ],
            url = Api.queryGoodsInfo;
        this._createModal(
            title,
            filter,
            table,
            url,
            (select)=>{
                callback(select);
            }
        ).show();
    },
    /**
     * 配件代码
     * @param callback
     */
    _queryMountings: function(callback, url = Api.getPart) {
        const title = '配件代码',
            filter = [
                {name:'配件名称',column:'partName'},
                {name:'品牌名称',column:'branchName'},
                {name:'分类名称',column:'categoryName'}
            ],
            table = [
                {name:'配件代码',column:'goodCode'},
                {name:'配件名称',column:'goodName'},
                {name:'品牌名称',column:'brandName'},
                {name:'分类名称',column:'cateName'}
            ];
            this._createModal(
                title,
                filter,
                table,
                url,
                (select)=>{
                    callback(select);
                }
            ).show();
    },
    /**
     * 措施代码
     * @param callback
     */
    _queryMeasure: function(callback) {
        const title = '措施代码',
            filter = [
                {name:'措施代码',column:'measureCode'},
                {name:'措施名称',column:'measureName'}
            ],
            table = [
                {name:'措施代码',column:'measureCode'},
                {name:'措施名称',column:'measureName'},
                {name:'措施单价',column:'measureMoney'}
            ],
            url = Api.getMeasure;
            this._createModal(
                title,
                filter,
                table,
                url,
                (select)=>{
                    callback(select);
                }
            ).show();
    },
    /**
     * 时间编辑
     * @param options
     * @param callback
     * @private
     */
    _choiceTime: function(options,callback){
        let timeDialog = new TimeDialog(options,callback);
        timeDialog.show();
    }
}